package com.nbsaas.boot.example.rest.convert;

import com.nbsaas.boot.example.data.entity.Example;
import com.nbsaas.boot.example.api.domain.request.ExampleRequest;

import org.springframework.beans.BeanUtils;
import com.nbsaas.boot.rest.api.Converter;
import com.nbsaas.boot.utils.BeanDataUtils;
            import com.nbsaas.boot.jpa.data.entity.User;
            import com.nbsaas.boot.example.data.entity.ExampleCatalog;

/**
* 客户案例请求对象转换成实体对象
*/

public class ExampleEntityConvert  implements Converter<Example, ExampleRequest> {

    @Override
    public Example convert(ExampleRequest source) {
        Example result = new Example();
        BeanDataUtils.copyProperties(source, result);
                    if(source.getCreator()!=null){
                    User creator =new User();
                    creator.setId(source.getCreator());
                    result.setCreator(creator);
                    }
                    if(source.getExampleCatalog()!=null){
                    ExampleCatalog exampleCatalog =new ExampleCatalog();
                    exampleCatalog.setId(source.getExampleCatalog());
                    result.setExampleCatalog(exampleCatalog);
                    }
        return result;
    }
}

